package cn.opopopo.design_pattern_learn.行为型.中介者.demo1;

import java.util.ArrayList;
import java.util.List;

// 具体中介者 - 聊天室
public class ChatRoom extends Mediator {

    private List<Colleague> users;
    
    public ChatRoom() {
        this.users = new ArrayList<>();
    }
    
    @Override
    public void addUser(Colleague colleague) {
        users.add(colleague);
    }
    
    @Override
    public void sendMessage(String message, Colleague sender) {



        // 将消息转发给所有其他用户
        for (Colleague user : users) {
            if (user != sender) {
                user.receiveMessage(message, sender.name);
            }
        }
    }
}